﻿using System;
using CompactMapper.Orm.Contracts;
using CompactMapper.Orm.UnitOfWork;
using CompactMapper.Orm.UnitOfWork.Mappings;

namespace CompactMapper.Orm.Tests
{
    public class OrmInMemoryTest
    {
        private readonly UnitOfWorkFactory _unitOfWorkFactory;

        private UnitOfWorkFactory UnitOfWorkFactory
        {
            get { return _unitOfWorkFactory; }
        }

        protected OrmInMemoryTest()
        {
            var assemblyStrings = new[]
                                      {
                                          typeof (Artist).Assembly.FullName
                                      };

            _unitOfWorkFactory = new UnitOfWorkFactory(assemblyStrings, "Data Source=:memory:;Version=3;New=true;BinaryGUID=True;");
        }

        internal IKeyedSqLiteUnitOfWork<T> GetKeyedUnitOfWork<T>() where T : class, IKeyedPersistent
        {
            return UnitOfWorkFactory.GetKeyedUnitOfWork<T>();
        }
        internal IKeyedSqLiteUnitOfWork<T> GetKeyedUnitOfWork<T>(IMappings mappings) where T : class, IKeyedPersistent
        {
            return UnitOfWorkFactory.GetKeyedUnitOfWork<T>(mappings);
        }
    }

    public class MusicDatabaseTestsBase : OrmInMemoryTest
    {
        protected MusicDatabaseTestsBase()
        {
            MusicDatabasePopulation.Populate(GetKeyedUnitOfWork<Artist>());
            MusicDatabasePopulation.Populate(GetKeyedUnitOfWork<Label>());
        }
    }
}
